package com.beidu.lottery.call.service.portal.validator.impl;

import com.beidu.lottery.call.constant.ActivityTypeEnum;
import com.beidu.lottery.call.entity.PortalActivityRule;
import com.beidu.lottery.call.exception.ServiceException;
import com.beidu.lottery.call.service.portal.validator.AbstractValidator;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.List;

/**
 * 投票规则校验 实现类
 *
 * @author 北渡
 */
@Slf4j
@Service
@SuppressWarnings("unused")
public class VoteValidator extends AbstractValidator {

    /**
     * 需要执行的校验函数
     * <p>
     * TODO 扩展
     */
    private final List<String> methods = Arrays.asList(
            "activityDateValidate", // 活动时间校验
            "whiteListValidate", // 白名单校验
            "voteTimesValidate", // 投票次数校验
            "pointsValidate"); // 积分校验

    @Override
    protected ActivityTypeEnum getActivityType() {
        return ActivityTypeEnum.VOTE;
    }

    @Override
    protected List<String> getMethods() {
        return methods;
    }

    /**
     * 投票次数校验
     *
     * @author 北渡
     */
    public void voteTimesValidate(PortalActivityRule rule) {
        // 查询剩余投票次数（用户当日剩余或总数剩余）
        Integer times = userDataService.queryVoteRemainingTimes(rule);
        if (times < 1) {
            throw new ServiceException(ErrorMessage.VOTE_QUOTA_FULL.getMsg());
        }
    }

}
